package sun.superstring.gui2;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Test2 {
    public static void main(String[] args) {
        // 第一种写法：直接提供实现类，用于创建事件监听对象
        JFrame win = new JFrame("登录窗口");

        JPanel panel = new JPanel();
        win.add(panel);

        win.setSize(500,400); // 窗口大小
        win.setLocationRelativeTo(null); // 居中显示
        win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  // 点击关闭按钮，程序退出

        JButton btn = new JButton("登录");
        panel.add(btn);
        btn.addActionListener(new MyActionListener(win));

        win.setVisible(true);  // 显示窗口

    }
}

class MyActionListener implements ActionListener {
    private JFrame win;
    public MyActionListener(JFrame win) {
        this.win = win;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        JOptionPane.showMessageDialog(win, "有人点击了登录！");
    }
}